package org.alex.samples.dao;

import java.util.ArrayList;
import java.util.List;

//import org.alex.samples.model.ExamSubject;
import org.alex.samples.model.ExamTest;
//import org.alex.samples.model.ExamTestType;
//import org.alex.samples.model.ExamTestVO;
//import org.alex.samples.model.ManageTest;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
//import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamTestDAOImpl extends BaseHibernateDAO<ExamTest> implements IExamTestDAO {

	@SuppressWarnings("unused")
	private static final String UserJDBC = null;
	@Autowired
	private SessionFactory sessionFactory;

	public Session getSession() {
		return this.sessionFactory.getCurrentSession();

	}

	
	//新增试题方法
	@Override
	public void addExamTest(ExamTest examTest) {
		this.save(examTest);
		
	}

//删除考题方法
	@Override
	public void deleteTest(Integer testId) {
		ExamTest exsitsTest=this.get(testId);
		if(exsitsTest!=null){
			this.delete(exsitsTest);
		}
		
	}

	//修改考题方法
	@Override
	public void editExamTest(ExamTest examTest) {
		this.update(examTest);
	}


	@Override
	public List<ExamTest> getTestListBySubAndTestType(Integer subId, Integer testTypeId) {
		return this.find("FROM ExamTest AS et WHERE et.subId=? AND et.examTestType.id=?", new Object[]{subId, testTypeId});
	}


	@Override
	public List<ExamTest> getTestListByIdList(List<Integer> randomTestIdList) {
		List<ExamTest> testList = new ArrayList<ExamTest>();
		for(Integer id : randomTestIdList){
			ExamTest test = this.get(id);
			testList.add(test);
		}
		return testList;
	}


	
	
	

	
	
	

/*	//新增试题方法
	public void createExamSubject(ManageTest manageTest) {
		if(manageTest!=null){
		Session session=getSession();
		ExamSubject examSubject=new ExamSubject();
		//examSubject.setId(UUID.randomUUID().toString())
		//examSubject.setSubId(20);
		System.out.println("1");
		examSubject.setSubId(9);
		examSubject.setName(manageTest.getExamSubject().getName());
		session.save(examSubject);
		System.out.println(examSubject.getName());
		
		ExamTestType examTestType=new ExamTestType();
		examTestType.setTestType(manageTest.getExamTestType().getTestType());
		examTestType.setTestTypeScore(manageTest.getExamTestType().getTestTypeScore());
		session.save(examTestType);
		System.out.println(examTestType.getTestTypeScore());
		
		manageTest.setExamSubject(examSubject);
		manageTest.setExamTestType(examTestType);
		
		session.save(manageTest);
		}else{
			System.out.println("manageTest is null");
		}
	}*/
	
	
	
}
